package com.xrtn.controller;

import com.xrtn.ApiVersion;
import com.xrtn.bean.*;
import com.xrtn.service.ICommonService;
import com.xrtn.service.IDoctorService;
import com.xrtn.utils.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.aspectj.apache.bcel.classfile.Code;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.WebRequest;

import javax.servlet.http.HttpServletRequest;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by tu_pei on 2018/2/27.
 */
@Api("医师模块接口")
@Controller
@RequestMapping("/{version}/doctor")
public class DoctorController {

    @Autowired
    private ICommonService commonService;

    @Autowired
    private IDoctorService doctorService;

    /**
     * @Title: selectTherapySchedule
     * @Description: 根据患者id查询患者诊疗进度
     * @param @param userId
     * @param @return
     * @return ResponseData
     * @throws
     */
    @ApiOperation(value = "根据患者id查询患者诊疗进度",notes="根据患者id查询患者诊疗进度")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="userId",dataType="int",required=true,value="患者id",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="bookingId",dataType="int",required=true,value="预约id",defaultValue = "1"),
    })
    @RequestMapping(value = "/selectTherapySchedule")
    @ApiVersion(1)
    @ResponseBody
    public ResponseData selectTherapySchedule(Integer userId,Integer bookingId){

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service
        data.setResults(doctorService.selectTherapySchedule(userId, bookingId));
        // 返回数据
        return data;
    }

    /**
     * @Title: selectTherapyScheduleState
     * @Description: 根据患者id查询患者诊疗进度
     * @param @param userId
     * @param @return
     * @return ResponseData
     * @throws
     */
    @ApiOperation(value = "根据患者id查询患者诊疗进度",notes="根据患者id查询患者诊疗进度")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="userId",dataType="int",required=true,value="患者id",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="bookingId",dataType="int",required=true,value="预约id",defaultValue = "1"),
    })
    @RequestMapping(value = "/selectTherapyScheduleState")
    @ApiVersion(1)
    @ResponseBody
    public ResponseData selectTherapyScheduleState(Integer userId,Integer bookingId){

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service
        data.setResults(doctorService.selectTherapyScheduleState(userId, bookingId));
        // 返回数据
        return data;
    }

    /**
     * @Title: saveDoctorPush
     * @Description: 确认问卷调查
     * @param @param userId
     * @param @return
     * @return ResponseData
     * @throws
     */
    @ApiOperation(value = "确认问卷调查",notes="确认问卷调查")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="userId",dataType="int",required=true,value="家长id",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="bookingId",dataType="int",required=true,value="预约id",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="doctorId",dataType="int",required=true,value="医师Id",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="patientId",dataType="int",required=true,value="患者id",defaultValue = "1"),
    })
    @RequestMapping(value = "/saveDoctorPush")
    @ApiVersion(1)
    @ResponseBody
    public ResponseData saveDoctorPush(TDoctorPushRel doctorPushRel){

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service
        data.setResults(commonService.saveDoctorPush(doctorPushRel));
        // 返回数据
        return data;
    }
    /**
     * @Title: selectPatientList
     * @Description: 获取用户患者列表
     * @param @param userId
     * @param @return
     * @return ResponseData
     * @throws
     */
    @ApiOperation(value = "获取用户患者列表",notes="获取用户患者列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="userId",dataType="int",required=true,value="用户id",defaultValue = "1"),
    })
    @RequestMapping(value = "/selectPatientList")
    @ApiVersion(1)
    @ResponseBody
    public ResponseData selectPatientList(Integer userId){

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service
        List<TPatientInfo> patientList = commonService.selectPatientListByUserId(userId);

        data.setResults(patientList);
        // 返回数据
        return data;
    }

    /**
     * @Title: updateBookingInfo
     * @Description: 修改预约信息
     * @param @param bookingId
     * @param @return
     * @return ResponseData
     * @throws
     */
    @ApiOperation(value = "修改预约信息",notes="获取用户患者列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="bookingId",dataType="int",required=true,value="预约id",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="patientId",dataType="int",required=true,value="患者id",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="userId",dataType="int",required=true,value="会员id",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="bookingType",dataType="int",required=true,value="0调理身体，1开始新疗程，",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="bookingDesc",dataType="int",required=true,value="预约备注",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="isAdd",dataType="int",required=true,value="1开启新病程，0继续治疗",defaultValue = "1"),
    })
    @RequestMapping(value = "/updateBookingInfo")
    @ApiVersion(1)
    @ResponseBody
    public ResponseData updateBookingInfo(TBookingInfo bookingInfo,String patientName,String patientBirthday,Integer patientGender){

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service
        commonService.updateBookingInfo(bookingInfo, patientName, patientBirthday, patientGender);
        // 返回数据
        return data;
    }

    /**
     * @Title: savePatient
     * @Description: 新增患者
     * @param @param userId
     * @param @return
     * @return ResponseData
     * @throws
     */
    @ApiOperation(value = "新增患者",notes="新增患者")
    @RequestMapping(value = "/savePatient")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="userId",dataType="int",required=true,value="用户id(家长id)",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="bookingId",dataType="int",required=true,value="预约单号",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="patientName",dataType="string",required=true,value="患者姓名",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="patientImg",dataType="string",required=true,value="患者头像",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="patientAge",dataType="int",required=true,value="患者年龄",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="patientGender",dataType="int",required=true,value="患者性别：0:男;1:女",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="patientHeight",dataType="int",required=true,value="患者身高",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="patientBodyWeight",dataType="int",required=true,value="患者体重",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="patientAddress",dataType="string",required=true,value="患者地址",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="patientDesc",dataType="string",required=true,value="备注",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="patientBirthday",dataType="string",required=true,value="生日",defaultValue = "1"),
    })
    @ApiVersion(1)
    @ResponseBody
    public ResponseData savePatient(TPatientInfo patientInfo,Integer bookingId){


        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service
        CodeEnum codeEnum = ObjUtils.validateParams(new Object[]{patientInfo.getPatientName(),
                patientInfo.getPatientGender(),patientInfo.getPatientAge()});
        patientInfo.setCreateTime(new Date());

        if(ObjUtils.isNotEmpty(codeEnum)){
            data.setCodeEnum(codeEnum);
            return data;
        }

        if(ObjUtils.isNotEmpty(patientInfo.getPatientHeight())){
            if(patientInfo.getPatientHeight() > 400){
                data.setCodeEnum(CodeEnum.CODE_60021);
                return data;
            }
        }

        if(ObjUtils.isNotEmpty(patientInfo.getPatientBodyWeight())){
            if( patientInfo.getPatientBodyWeight() >400){
                data.setCodeEnum(CodeEnum.CODE_60021);
                return data;
            }
        }

        int count = commonService.insertTPatientInfoSelective(patientInfo);



        TPatientInit patientInit = new TPatientInit();
        patientInit.setBookingId(bookingId);
        patientInit.setPatientId(patientInfo.getPatientId());
        patientInit.setUserName(patientInfo.getPatientName());
        patientInit.setUserImg(patientInfo.getPatientImg());
        patientInit.setUserAge(patientInfo.getPatientAge());
        patientInit.setUserGender(patientInfo.getPatientGender());
        patientInit.setUserHeight(patientInfo.getPatientHeight());
        patientInit.setUserBodyWeight(patientInfo.getPatientBodyWeight());
        patientInit.setUserAddress(patientInfo.getPatientAddress());
        patientInit.setUserDesc(patientInfo.getPatientDesc());
        patientInit.setUserBirthday(patientInfo.getPatientBirthday());

        commonService.insertTPatientInitSelective(patientInit);

        if(count < 0 ){
            data.setCodeEnum(CodeEnum.CODE_20001);
        }

        Map<String,Object> retMap = new HashMap<>();
        retMap.put("patientId", count);
        data.setResults(retMap);
        // 返回数据
        return data;
    }
    /**
     * @Title: selectPatientInit
     * @Description: 查询基础信息调查表
     * @param @param userId
     * @param @return
     * @return ResponseData
     * @throws
     */
    @ApiOperation(value = "查询基础信息调查表",notes="查询基础信息调查表")
    @RequestMapping(value = "/selectPatientInit")
    @ApiImplicitParams({
            //@ApiImplicitParam(paramType="query",name="bookingId",dataType="int",required=true,value="预约单号",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="patientId",dataType="int",required=true,value="患者id",defaultValue = "1"),
    })
    @ApiVersion(1)
    @ResponseBody
    public ResponseData selectPatientInit(Integer bookingId,Integer patientId){

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service
        Map<String,Object> params = new HashMap<>();
        //params.put("bookingId", bookingId);
        params.put("patientId", patientId);

        data.setResults(commonService.selectTPatientInitByMap(params));
        // 返回数据
        return data;
    }
    /**
     * @Title: selectPatientInfo
     * @Description: 查询基础信息调查表
     * @param @param userId
     * @param @return
     * @return ResponseData
     * @throws
     */
    @ApiOperation(value = "查询基础信息调查表",notes="查询基础信息调查表")
    @RequestMapping(value = "/selectPatientInfo", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="patientId",dataType="int",required=true,value="患者id",defaultValue = "1"),
    })
    @ApiVersion(1)
    @ResponseBody
    public ResponseData selectPatientInfo(Integer patientId){

        // 创建响应Model
        ResponseData data = new ResponseData();

        data.setResults(commonService.selectTPatientInfo(patientId));
        // 返回数据
        return data;
    }
    /**
     * @Title: savePatientInit
     * @Description: 新增基础信息调查表
     * @param @param userId
     * @param @return
     * @return ResponseData
     * @throws
     */
    @ApiOperation(value = "新增基础信息调查表",notes="新增基础信息调查表")
    @RequestMapping(value = "/savePatientInit")
    @ApiImplicitParams({
            //@ApiImplicitParam(paramType="query",name="bookingId",dataType="int",required=true,value="预约单号",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="patientId",dataType="int",required=true,value="患者id",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="userName",dataType="string",required=true,value="患者姓名",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="userGender",dataType="int",required=true,value="患者性别：0:男;1:女",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="userBirthday",dataType="string",required=true,value="生日",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="userHeight",dataType="int",required=true,value="身高",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="userBodyWeight",dataType="int",required=true,value="体重",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="userAddress",dataType="int",required=true,value="地址",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="userDesc",dataType="int",required=true,value="备注",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="userAge",dataType="int",required=true,value="年龄",defaultValue = "1"),
    })
    @ApiVersion(1)
    @ResponseBody
    public ResponseData savePatientInit(TPatientInit patientInit){

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service
        CodeEnum codeEnum = ObjUtils.validateParams(new Object[]{patientInit.getUserName(),
                patientInit.getUserGender(),patientInit.getUserAddress(),patientInit.getUserBirthday(),
                patientInit.getUserBodyWeight(),patientInit.getUserHeight(),patientInit.getUserDesc()});
        patientInit.setCreateTime(new Date());

        if(ObjUtils.isNotEmpty(patientInit.getUserHeight())){
            if(patientInit.getUserHeight() > 400){
                data.setCodeEnum(CodeEnum.CODE_60021);
                return data;
            }
        }

        if(ObjUtils.isNotEmpty(patientInit.getUserBodyWeight())){
            if( patientInit.getUserBodyWeight() >400){
                data.setCodeEnum(CodeEnum.CODE_60021);
                return data;
            }
        }

        int count = commonService.insertTPatientInitSelective(patientInit);

        if(count < 0 ){
            data.setCodeEnum(CodeEnum.CODE_20002);
        }

        // 返回数据
        return data;
    }

    /**
     * @Title: updatePatientInit
     * @Description: 修改基础信息调查表
     * @param @param userId
     * @param @return
     * @return ResponseData
     * @throws
     */
    @ApiOperation(value = "修改基础信息调查表",notes="修改基础信息调查表")
    @RequestMapping(value = "/updatePatientInit")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="relId",dataType="int",required=true,value="主键id",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="userName",dataType="string",required=true,value="患者姓名",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="userGender",dataType="int",required=true,value="患者性别：0:男;1:女",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="userBirthday",dataType="string",required=true,value="生日",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="userHeight",dataType="int",required=true,value="身高",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="userBodyWeight",dataType="int",required=true,value="体重",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="userAddress",dataType="int",required=true,value="地址",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="userImg",dataType="int",required=true,value="头像",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="userDesc",dataType="int",required=true,value="备注",defaultValue = "1"),
    })
    @ApiVersion(1)
    @ResponseBody
    public ResponseData updatePatientInit(TPatientInit patientInit){

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service

        if(ObjUtils.isNotEmpty(patientInit.getUserHeight())){
            if(patientInit.getUserHeight() > 400){
                data.setCodeEnum(CodeEnum.CODE_60021);
                return data;
            }
        }

        if(ObjUtils.isNotEmpty(patientInit.getUserBodyWeight())){
            if( patientInit.getUserBodyWeight() >400){
                data.setCodeEnum(CodeEnum.CODE_60021);
                return data;
            }
        }

        int count = commonService.updateTPatientInitSelective(patientInit);
        if(count < 0 ){
            data.setCodeEnum(CodeEnum.CODE_20002);
        }
        // 返回数据
        return data;
    }



    /**
     * @Title: selectPatientHistory
     * @Description: 获取患者病历档案
     * @param @param userId
     * @param @return
     * @return ResponseData
     * @throws
     */
    @ApiOperation(value = "获取患者病历档案",notes="获取患者病历档案")
    @RequestMapping(value = "/selectPatientHistory")
    @ApiVersion(1)
    @ResponseBody
    public ResponseData selectPatientHistory(Integer patientId){

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service

        TPatientHistory patientHistory = commonService.selectPatientHistoryByPatientId(patientId);

        data.setResults(patientHistory);

        // 返回数据
        return data;
    }

    /**
     * @Title: updatePatientHistory
     * @Description: 修改患者病历档案
     * @param @param userId
     * @param @return
     * @return ResponseData
     * @throws
     */
    @ApiOperation(value = "修改患者病历档案",notes="修改患者病历档案")
    @RequestMapping(value = "/updatePatientHistory")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="historyId",dataType="int",required=true,value="病历Id",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="justNowHistory",dataType="string",required=true,value="现病史",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="allergyHistory",dataType="int",required=true,value="过敏史",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="userHistory",dataType="string",required=true,value="个人史",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="familyHistory",dataType="int",required=true,value="家族史",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="vaccineHistory",dataType="int",required=true,value="疫苗接种历史",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="laboratoryHistory",dataType="int",required=true,value="实验室辅助检查",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="medicineHistory",dataType="int",required=false,value="用药史",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="feverHistory",dataType="int",required=false,value="高烧惊厥史",defaultValue = "1"),
    })
    @ApiVersion(1)
    @ResponseBody
    public ResponseData updatePatientHistory(TPatientHistory patientHistory){

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service

        int count = commonService.updatePatientHistorySelective(patientHistory);

        if(count < 0){
            data.setCodeEnum(CodeEnum.CODE_20004);
        }

        // 返回数据
        return data;
    }

    /**
     * @Title: savePatientHistory
     * @Description: 新增患者病历档案
     * @param @param userId
     * @param @return
     * @return ResponseData
     * @throws
     */
    @ApiOperation(value = "新增患者病历档案",notes="新增患者病历档案")
    @RequestMapping(value = "/savePatientHistory")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="userId",dataType="int",required=true,value="患者id",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="justNowHistory",dataType="string",required=true,value="现病史",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="allergyHistory",dataType="int",required=true,value="过敏史",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="userHistory",dataType="string",required=true,value="个人史",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="familyHistory",dataType="int",required=true,value="家族史",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="vaccineHistory",dataType="int",required=true,value="疫苗接种历史",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="laboratoryHistory",dataType="int",required=true,value="实验室辅助检查",defaultValue = "1"),
    })
    @ApiVersion(1)
    @ResponseBody
    public ResponseData savePatientHistory(TPatientHistory patientHistory){

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service

        int count = commonService.insertPatientHistorySelective(patientHistory);

        if(count < 0){
            data.setCodeEnum(CodeEnum.CODE_20003);
        }

        // 返回数据
        return data;
    }

    /**
     * @Title: selectOrderList
     * @Description: 获取患者就诊记录
     * @param @param userId
     * @param @return
     * @return ResponseData
     * @throws
     */
    @ApiOperation(value = "获取患者就诊记录",notes="获取患者就诊记录")
    @RequestMapping(value = "/selectOrderList")
    @ApiVersion(1)
    @ResponseBody
    public ResponseData selectOrderList(HttpServletRequest request,Integer patientId){

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service
        Map<String,Object> params = HttpUtils.getAllReqParams(request);

        List<Map<String,Object>> patientList = commonService.selectPatientList(params);

        data.setResults(patientList);

        // 返回数据
        return data;
    }
    /**
     * @Title: saveTreatmentInfo
     * @Description: 保存患者病历详情
     * @param @param userId
     * @param @return
     * @return ResponseData
     * @throws
     */
    @ApiOperation(value = "保存患者病历详情",notes="保存患者病历详情")
    @RequestMapping(value = "/saveTreatmentInfo")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="treatmentId",dataType="int",required=false,value="病历id",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="userId",dataType="int",required=true,value="用户id(家长id)",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="patientId",dataType="int",required=true,value="患者id",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="bookingId",dataType="int",required=true,value="预约id",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="diseaseTime",dataType="string",required=true,value="发病时间",defaultValue = "2018-03-02"),
            @ApiImplicitParam(paramType="query",name="diseaseInfo",dataType="string",required=true,value="主诉",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="diseaseScore",dataType="int",required=true,value="分值",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="treatmentInit",dataType="string",required=true,value="初步就诊",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="treatmentOpinion",dataType="string",required=true,value="治疗意见",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="treatmentRemarks",dataType="string",required=true,value="备注",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="treatmentImg",dataType="string",required=true,value="舌苔图片",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="handsImg",dataType="string",required=true,value="手部图片",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="faceImg",dataType="string",required=true,value="脸部图片",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="pointArray",dataType="string",required=true,value="穴位多选数组,userId:家长ID，diseaseId：穴位id，typeId:类型id（如：头部）",defaultValue = "[{\"userId\":1,\"bookingId\":1,\"patientId\":1,\"doctorId\":1,\"typeId\":1,\"pointId\":1,\"typeName\":111,\"pointName\":123}]"),
            @ApiImplicitParam(paramType="query",name="diseaseArray",dataType="string",required=true,value="病症多选数组(主症和兼症)，userId:家长ID，pointId：病症程度id，typeId:类型id（如：咳嗽）",defaultValue = "[{\"userId\":1,\"bookingId\":1,\"patientId\":1,\"doctorId\":1,\"typeId\":1,\"diseaseId\":1,\"typeName\":111,\"diseaseName\":123,\"isMain\":1}]"),
            @ApiImplicitParam(paramType="query",name="conclusionArray",dataType="string",required=true,value="诊断结论：",defaultValue="[{\"userId\":1,\"bookingId\":1,\"patientId\":1,\"doctorId\":1,\"conclusionId\":1,\"conclusionName\":1}]"),
            @ApiImplicitParam(paramType="query",name="infoIds",dataType="string",value="特病选项ids：",defaultValue="[1,2]"),
    })
    @ApiVersion(1)
    @ResponseBody
    public ResponseData saveTreatmentInfo(TPatientTreatment patientTreatment ,String bookingName,String bookingPhone,String bookingPhones,
                                          Integer doctorId,Integer subclinicId,String pointArray,String diseaseArray,String conclusionArray,
                                          String infoIds, Integer specialId, Integer checkResult, Integer realResult, Integer error){

        // 创建响应Model
        ResponseData data = new ResponseData();
        //空校验
        CodeEnum codeEnum = ObjUtils.validateParams(new Object[]{patientTreatment.getBookingId(),
                patientTreatment.getPatientId(),patientTreatment.getDiseaseInfo(),patientTreatment.getUserId(),
                patientTreatment.getTreatmentInit(),patientTreatment.getTreatmentOpinion(),patientTreatment.getTreatmentRemarks(),
                patientTreatment.getTreatmentImg(), patientTreatment.getFaceImg(), patientTreatment.getHandsImg(),pointArray,diseaseArray});
        if(ObjUtils.isNotEmpty(codeEnum)){
            data.setCodeEnum(codeEnum);
            return data;
        }

        Integer treatmentId = 0;
        patientTreatment.setTreatmentTime(new Date());

        if(ObjUtils.isNotEmpty(patientTreatment.getBookingId())){
            Map<String,Object> params = new HashMap<>();
            params.put("bookingId", patientTreatment.getBookingId());
            if(ObjUtils.isNotEmpty(patientTreatment.getPatientId())){
                params.put("patientId", patientTreatment.getPatientId());
            }
            TPatientTreatment treatment = commonService.selectPatientTreatmentInfo(params);
            if(ObjUtils.isNotEmpty(treatment)){
                patientTreatment.setTreatmentId(treatment.getTreatmentId());
            }
        }

        if(ObjUtils.isEmpty(patientTreatment.getTreatmentId())){
            treatmentId = doctorService.saveTreatmentInfo(patientTreatment , bookingName, bookingPhone, bookingPhones,
                    doctorId,subclinicId, pointArray, diseaseArray, conclusionArray,
                    infoIds, specialId, checkResult, realResult, error);
        }else{
            treatmentId = patientTreatment.getTreatmentId();
            patientTreatment.setCreateTime(new Date());
            Integer updateResult = doctorService.updateTreatmentInfo(patientTreatment , pointArray, diseaseArray, conclusionArray,
                    infoIds, specialId, checkResult, realResult, error);
            if (updateResult == -2) {
                data.setCodeEnum(CodeEnum.CODE_30013);
                return data;
            }
        }
        if( treatmentId < 0 ){
            data.setCodeEnum(CodeEnum.CODE_90001);
            return data;
        }
        if (treatmentId > 0){
          data.setResults(treatmentId);
        }
        // 返回数据
        return data;
    }
    @InitBinder
    public void initBinder(WebDataBinder binder, WebRequest request) {

        //转换日期
        DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));// CustomDateEditor为自定义日期编辑器
    }
    /**
     * @Title: selectTreatmentInfo
     * @Description: 获取患者病历详情
     * @param @param userId
     * @param @return
     * @return ResponseData
     * @throws
     */
    @ApiOperation(value = "获取患者病历详情",notes="获取患者病历详情")
    @RequestMapping(value = "/selectTreatmentInfo")
    @ApiVersion(1)
    @ResponseBody
    public ResponseData selectTreatmentInfo(Integer bookingId,Integer patientId){

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 返回数据
        return doctorService.selectTreatmentInfo(bookingId, patientId);
    }



    /**
     * @Title: selectHistoryTreatmentList
     * @Description: 获取历史病历信息
     * @param @param userId
     * @param @return
     * @return ResponseData
     * @throws
     */
    @ApiOperation(value = "获取历史病历列表",notes="获取历史病历列表")
    @RequestMapping(value = "/selectHistoryTreatmentList")
    @ApiVersion(1)
    @ResponseBody
    public ResponseData selectHistoryTreatmentList(Integer patientId){

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 返回数据
        return doctorService.selectHistoryTreatmentList(patientId, data);
    }

    /**
     * @Title: updateBookingState
     * @Description: 修改预约单状态
     * @param @param userId
     * @param @return
     * @return ResponseData
     * @throws
     */
    @ApiOperation(value = "修改预约单状态",notes="修改预约单状态")
    @RequestMapping(value = "/updateBookingState")
    @ApiVersion(1)
    @ResponseBody
    public ResponseData updateBookingState(Integer bookingId){

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 返回数据
        data.setResults(doctorService.updateBookingState(bookingId));
        return data;
    }
}
